package _thread_lock._atomic;

import java.util.concurrent.atomic.AtomicReferenceFieldUpdater;

/**
 * @Author: huangya
 * @Date: 2020/11/02
 * @Description:
 */
public class AtomicReferenceFieldUpdaterDemo {

    public static void main(String[] args) {
        AtomicReferenceFieldUpdater updater = AtomicReferenceFieldUpdater.newUpdater(
                Dog.class, String.class, "name");
        Dog dog1 = new Dog();
        updater.compareAndSet(dog1, dog1.name, "test");
        System.out.println(dog1.name);
    }

    static class Dog {
        volatile String name = "dog1";

    }
}


